PanelMgr = {};

local panelDic = {};
local mainPanel = nil;

function PanelMgr:show(panel)
    local p = panelDic[panel.prefabPath];
    if p ~= nil and mainPanel == p then
        return;
    end
    if p == nil then
        panelDic[panel.prefabPath] = panel;
        p = panel;
    end
    if mainPanel ~= p then
        if mainPanel ~= nil then
            mainPanel:hide();
        end
        TimeMgr:removeDelayFun(p.delayDestroyHandler);
        p:setVisible(true);
        UIRoot.windowMask.gameObject:SetActive(true);
        mainPanel = p;
    end
    if not p.isInit then
        p:setParent(UIRoot.window);
        p:loadPrefab();
    end
end

function PanelMgr:hide(panel)
    local p = panelDic[panel.prefabPath];
    if p == nil then
        return;
    end
    p:setVisible(false);
    if p == mainPanel then
        mainPanel = nil;
        UIRoot.windowMask.gameObject:SetActive(false);
    end

    p.delayDestroyHandler=TimeMgr:delayFun(10,function ()
        p:destroy();
    end);
end

function PanelMgr:getMainPanel()
    return mainPanel;
end